package ru.st.selenium.applogic1;

import java.util.List;

import ru.st.selenium.applogic.FilmHelper;
import ru.st.selenium.model.Film;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class FilmHelper1 extends DriverBasedHelper implements FilmHelper {
	public FilmHelper1(ApplicationManager1 manager) {
		super(manager.getWebDriver());
		this.manager = manager;
	}

	private ApplicationManager1 manager;

	@Override
	public void addFilm(Film film) {
		
		driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")) 
		  .click();	  
		driver.findElement(By.name("name"))
		  .sendKeys(film.getTitle());	  
		driver.findElement(By.name("year"))  
		  .sendKeys(film.getYear());
		driver.findElement(By.id("submit"))
		  .click();	  
	}

	@Override
	public void deleteFilm(Film film) {
		List<WebElement> elements = driver.findElements(By.className("movie_box"));
	      elements.get(0)
	        .click();
		  driver.findElement(By.cssSelector("img[alt=\"Remove\"]"))
		    .click();	      
	}
/*
	@Override
	public boolean isCreated(Film film) {
		manager.getNavigationHelper().openMainPage();
		List<WebElement> films = driver.findElements(By.cssSelector("div.title"));

		for(WebElement filmElement: films) {
			if(filmElement.getText().contains(film.getTitle())) {
				return true;
			}
		
		}
		return false;
	}

	@Override
	public boolean isNotCreated(Film film) {
		manager.getNavigationHelper().openMainPage();
		List<WebElement> films = driver.findElements(By.cssSelector("div.title"));

		for(WebElement filmElement: films) {
			if(filmElement.getText().contains(film.getTitle())) {
				return false;
			}	
		}
		return true;
	}
	*/

	@Override
	public List<Film> search(String title) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isCreated() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isNotCreated() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean filmsAreFound(String title) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean nothingIsFound(String title) {
		// TODO Auto-generated method stub
		return false;
	}
}
